package com.abbas.smartCity.ui.youthInn;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.abbas.smartCity.App;
import com.abbas.smartCity.R;
import com.abbas.smartCity.adapter.ListCommAdapter;
import com.abbas.smartCity.base.BaseActivity;
import com.abbas.smartCity.bean.inn.TalentPolicyAreaDetailBean;
import com.abbas.smartCity.bean.inn.TalentPolicyListBean;
import com.abbas.smartCity.retroft.ICallback;
import com.abbas.smartCity.view.MListView;
import com.bumptech.glide.Glide;

import java.util.List;

import retrofit2.Call;

public class TalentPeoplePolicyActivity extends BaseActivity {

    private ImageView im;
    private TextView tv;
    private MListView lv;
    private List<TalentPolicyListBean.DataBean> dataBeans;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_talent_people_policy;
    }

    @Override
    protected String setCustomTitle() {
        return "人才政策";
    }

    @Override
    protected void initView() {
        im = (ImageView) findViewById(R.id.im);
        tv = (TextView) findViewById(R.id.tv);
        lv = (MListView) findViewById(R.id.lv);

    }

    @Override
    protected void initData() {
        final int id = getIntent().getIntExtra("id", -1);

        api.getTalentPolicyAreaDetail(id).enqueue(new ICallback<TalentPolicyAreaDetailBean>() {
            @Override
            public void onSuccess(Call<TalentPolicyAreaDetailBean> call, TalentPolicyAreaDetailBean data) {
                final TalentPolicyAreaDetailBean.DataBean dataBean = data.getData();
                Glide.with(TalentPeoplePolicyActivity.this)
                        .load(App.getBaseUrl()+dataBean.getImgUrl())
                        .into(im);
                tv.setText(dataBean.getIntroduce());
            }
        });

        api.getTalentPolicyList(id).enqueue(new ICallback<TalentPolicyListBean>() {
            @Override
            public void onSuccess(Call<TalentPolicyListBean> call, TalentPolicyListBean data) {
                dataBeans = data.getData();
                lv.setAdapter(new ListCommAdapter<TalentPolicyListBean.DataBean, ListCommAdapter.TalentPolicyHolder>(
                        dataBeans,
                        ListCommAdapter.TalentPolicyHolder.class,
                        R.layout.talent_policy_item
                ) {
                    @Override
                    protected void show(TalentPolicyListBean.DataBean data, View convertView, TalentPolicyHolder viewHolder, int position, Context context) {
                        viewHolder.name.setText(data.getTitle());
                        viewHolder.sub.setText(data.getCreateTime());
                    }
                });
            }
        });
    }

    @Override
    protected void initEvent() {
        lv.setOnItemClickListener((adapterView, view, i, l) -> {
            final TalentPolicyListBean.DataBean dataBean = dataBeans.get(i);

            final Intent intent = new Intent(TalentPeoplePolicyActivity.this, TalentPolicyDetailActivity.class);
            intent.putExtra("id",dataBean.getId());
            startActivity(intent);
        });
    }
}